class Observe {
  constructor (data) {
    this.walk(data)
  }
  walk (data) {
    if (!data || typeof data !== 'object') return
    Object.keys(data).forEach(key => {
      this.defineReactive(data, key, data[key])
    })
  }
  defineReactive (data, key, val) {
    this.walk(val)
    let _this = this
    let dep = new Dep()
    Object.defineProperty(data, key, {
      get () {
        Dep.target && dep.addSub(Dep.target)
        return val
      },
      set (newValue) {
        if (newValue === val) return
        val = newValue
        _this.walk(val)
        dep.notify()
      }
    })
  }
}